********************************************************************************
** 	TITLE: e17_covid_cases.do
**
**	PROJECT: IGNITE
** 
**  PURPOSE: Appendix Figure XVII: COVID-19 Cases and Deaths over Time

********************************************************************************
**  PURPOSE: Create Graphs for the COVID period in Genesee and Saginaw counties
********************************************************************************

//Importing Covid data from NYT source: https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv
	//Archived in the Wayback Machine on 09/10/2024
import delimited "https://web.archive.org/web/20240910173131/https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv", clear

save "$output_data/covid_data/covid_data.dta", replace

use "$output_data/covid_data/covid_data.dta", clear

//Keeping Fips State + County Codes for Genesee County (26049) and Saginaw County (26145)
keep if inlist(fips,26049,26145)

gen new_date = date(date,"YMD")
format new_date %td

bysort fips (new_date): gen covid_cases = cases - cases[_n-1]
replace covid_cases = cases if new_date==td(19mar2020)
replace covid_cases = cases if new_date==td(21mar2020)

bysort fips (new_date): gen death_cases = deaths - deaths[_n-1]
replace death_cases = deaths if new_date==td(19mar2020)
replace death_cases = deaths if new_date==td(21mar2020)

keep new_date covid_cases death_cases fips
	
reshape wide covid_cases death_cases, i(new_date) j(fips)

gen month_booked = month(new_date)
gen year_booked = year(new_date)
gen ym_booked = ym(year_booked,month_booked)
format ym_booked %tm

collapse (sum) covid_cases26049 death_cases26049 covid_cases26145 death_cases26145, by(ym_booked)
gen covid_cases_gen_100 = (covid_cases26049/406211)*100000
gen covid_cases_sag_100 = (covid_cases26145/190124)*100000
gen death_cases_gen_100 = (death_cases26049/406211)*100000
gen death_cases_sag_100 = (death_cases26145/190124)*100000

twoway connected covid_cases_gen_100 covid_cases_sag_100 ym_booked, lcolor(ebblue cranberry) lpattern(solid solid) ///
legend(order(1 "Genesee" 2 "Saginaw") position(6) cols(2)) msymbol(D D) ///
ytitle("COVID Cases per 100,000 Population") xtitle("Month") msymbol(Dh Dh) graphregion(fcolor(white)) ///
bgcolor(white) yla(, nogrid) xla(, nogrid)

gr export "$figures/covid_cases_luciagll.pdf", replace

twoway connected death_cases_gen_100 death_cases_sag_100 ym_booked, lcolor(ebblue cranberry) lpattern(solid solid) ///
legend(order(1 "Genesee" 2 "Saginaw") position(6) cols(2)) msymbol(D D) ///
ytitle("COVID Deaths per 100,000 Population") xtitle("Month") msymbol(Dh Dh) graphregion(fcolor(white)) ///
bgcolor(white) yla(, nogrid) xla(, nogrid)

gr export "$figures/covid_deaths_luciagll.pdf", replace

		


